package swt.dao;

import java.sql.ResultSet;
import java.sql.SQLException;


import swt.entity.Tr;
import swt.util.DBHelp;
import swt.util.RowMapper;

public class TrDao {
	private DBHelp<Tr> db=new DBHelp<Tr>();
	
	public Tr findByTrName(String trname){
		String sql="select id ,trname,tel from t_tr where trname=?";
		return db.executeQueryForObject(sql, new CompRowMapper(), trname);
	}
	public Tr findByTrId(String trId){
		String sql="select id ,trname,tel from t_tr where id=?";
		return db.executeQueryForObject(sql, new CompRowMapper(), trId);
	}
	
	public void save(String trname,String id){
		String sql="insert into t_tr( trname,id) values(?,?)";
		db.executeSQL(sql,trname,id);
	}
	private class CompRowMapper implements RowMapper<Tr>{

		public Tr mapperRow(ResultSet rs) throws SQLException {
			
			Tr tr = new Tr();
			tr.setId(rs.getString("id"));
			tr.setTrname(rs.getString("trname"));
			tr.setTel(rs.getString("tel"));
			
			return tr;
		}
		
	}
}
